package com.example.easytraffic.core;

public class CountBasedProxyAction implements Runnable {

	private Runnable action;
	private int limit;
	private volatile int count;
	
	public CountBasedProxyAction(Runnable action, int limit) {
		super();
		this.count = 0;
		this.action = action;
		this.limit = limit;
	}

	public void run() {
		if (count < limit) {
			count++;
			action.run();
		}
		else {
			throw new TrafficEndedException();
		}
	}
	
}
